#include "xftp_port.hpp"

#include <glog/logging.h>

#include <string>
#include <vector>

#include <cstdlib>
xftp_port::xftp_port(/* args */)
{
}

xftp_port::~xftp_port()
{
}
void xftp_port::parse_cmd(std::string type,std::string msg)
{
    // 获取IP和端口，交由其他类进行连接

    std::vector<std::string> vals;
    std::string temp;
    for (size_t i = 5; i < msg.size(); i++)
    {
        if (msg[i] == ','||msg[i] == '\r')
        {
            /* code */
            
            vals.push_back(temp);
            temp = "";
            continue;
        }
        temp +=msg[i];  // 每次取,之前的
        
    }
    auto ret = check_ip(temp.c_str());
    VLOG(1)<<"check_ip is "<<ret;
    this->ip = vals[0]+"."+vals[1]+"."+vals[2]+"."+vals[3];
    this->port = atoi(vals[4].c_str())*25 + atoi(vals[5].c_str());
    VLOG(0)<<"PORT IP is "<<ip<<"  PORT port is "<<port;

    recv_cmd("200 PORT command successful .\r\n");
}

